package cn.cvs.service;

import cn.cvs.dao.PowerBatteryMapper;
import cn.cvs.pojo.PowerBattery;
import cn.cvs.utils.MybatisUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class PowerBatteryService {
    SqlSession sqlSession = MybatisUtil.createSqlSession();
    PowerBatteryMapper mapper = sqlSession.getMapper(PowerBatteryMapper.class);
    public List<PowerBattery>list(){
        List<PowerBattery>list = mapper.list();
        return list;
    }
    public PowerBattery update(Integer id){
        PowerBattery powerBattery = new PowerBattery();
        powerBattery = mapper.update(id);
        return powerBattery;
    }
    public int insert(PowerBattery powerBattery){
        int count = mapper.insert(powerBattery);
        if (count>0){
            sqlSession.commit();
        }else{
            sqlSession.rollback();
        }
        return count;
    }
    public int delete(int id){
        int count = mapper.delete(id);
        if (count>0){
            sqlSession.commit();
        }else{
            sqlSession.rollback();
        }
        return count;
    }
}
